<script>
  import RemoteDAO from '@/tools/remoteDAO'
  // import utils from '../tools/utils.js'
  import {mapActions} from 'vuex'
  import MessageBox from '../plugins/BUI/packages/message-box'

  export default {
    data () {
      return {
        isClose: false
      }
    },
    props: {
      momentId: Number,
      momentType: String
    },
    methods: {
      ...mapActions(['setSettingEnable', 'setRemoveCardId']),
      close (momentType, momentId) {
        if (!localStorage.getItem('userCode')) {
          RemoteDAO.callNativeLogin()
            .then(resp => {
              window.location.reload()
            })
          return false
        }
        MessageBox({
          title: '温馨提示',
          message: '确定要关闭这类消息的推送吗?',
          showCancelButton: true
        }).then(action => {
          if (action === 'confirm') {
            if (!this.isClose) {
              this.isClose = !this.isClose
              const className = this.$el.className
              this.$el.className = `${className} fade`
              this.setSettingEnable({
                name: momentType,
                value: false
              })
              setTimeout(() => {
                this.setRemoveCardId(momentId)
                let params = {
                  msgType: momentType,
                  userCode: localStorage.getItem('userCode'),
                  funcType: 'disable'
                }
                RemoteDAO.updateUserConfig(params)
                .then((res) => {
                }, err => {
                  this.$BMessage.show('系统繁忙，亲请稍候再试!')
                  throw err
                })
                this.isClose = !this.isClose
                this.$el.className = `${className}`
              }, 500)
            }
          } else {
            return false
          }
        })
      }
    }
  }
</script>
